package com.csliubo.eclipse.plugin.sqlgenerator.preferences;

import static com.csliubo.eclipse.plugin.sqlgenerator.constants.OutputFormat.EXCEL;
import static com.csliubo.eclipse.plugin.sqlgenerator.constants.OutputFormat.WIKI;

import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;


import com.csliubo.eclipse.plugin.sqlgenerator.Activator;
import com.csliubo.eclipse.plugin.sqlgenerator.constants.TabSize;

public class SqlGeneratorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    public SqlGeneratorPreferencePage() {
        super(GRID);
        setPreferenceStore(Activator.getDefault().getPreferenceStore());
        setDescription("数据库相关配置");
    }

    /**
     * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various
     * types of preferences. Each field editor knows how to save and restore itself.
     */
    public void createFieldEditors() {

        addField(new FileFieldEditor(PreferenceConstants.DRIVER_CLASS_LOCATION, "driver jar:", false,
                                     getFieldEditorParent()));
        addField(new StringFieldEditor(PreferenceConstants.JDBC_DRIVER_CLASS, "Driver class:", getFieldEditorParent()));
        addField(new StringFieldEditor(PreferenceConstants.JDBC_CONNECTION_URL, "connection url:",
                                       getFieldEditorParent()));
        addField(new StringFieldEditor(PreferenceConstants.DB_USER, "user:", getFieldEditorParent()));
        addField(new StringFieldEditor(PreferenceConstants.DB_PASSWORD, "password:", getFieldEditorParent()));
        addField(new ComboFieldEditor(PreferenceConstants.OUTPUT_FORMAT, "输出格式:", getOutpuFormatInfo(),
                                      getFieldEditorParent()));
        addField(new ComboFieldEditor(PreferenceConstants.TAB_SIZE, "tab :", getTabSizeInfo(), getFieldEditorParent()));
    }

    private String[][] getOutpuFormatInfo() {
        String[][] formatInfos = new String[2][2];
        formatInfos[0] = new String[] { "EXCEL", EXCEL.getValue() };
        formatInfos[1] = new String[] { "WIKI", WIKI.getValue() };
        return formatInfos;
    }

    private String[][] getTabSizeInfo() {
        String[][] formatInfos = new String[2][2];
        formatInfos[0] = new String[] { TabSize.FOUR.getDisplay(), TabSize.FOUR.getDisplay() };
        formatInfos[1] = new String[] { TabSize.EIGHT.getDisplay(), TabSize.EIGHT.getDisplay() };
        return formatInfos;
    }

    public void init(IWorkbench workbench) {
    }

}
